package com.jindianjichi.auth.domain.service.impl;

import com.jindianjichi.auth.common.enums.IsDeletedEnum;
import com.jindianjichi.auth.domain.BO.AuthRoleBO;
import com.jindianjichi.auth.domain.convert.AuthRoleBoConvert;
import com.jindianjichi.auth.domain.service.AuthRoleDomainService;
import com.jindianjichi.auth.domain.service.AuthUserDomainService;
import com.jindianjichi.auth.infra.basic.entity.AuthRole;
import com.jindianjichi.auth.infra.basic.service.AuthRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService{
    @Autowired
    private AuthRoleService authRoleService;
    @Override
    public Boolean add(AuthRoleBO authRoleBO) {
        AuthRole authRole = AuthRoleBoConvert.instance.convertToBoAuthRole(authRoleBO);
        authRole.setIsDeleted(IsDeletedEnum.UN_DELETED.getCode());
        int count = authRoleService.insert(authRole);
        return count > 0;
    }

    @Override
    public Boolean update(AuthRoleBO authRoleBO) {
        AuthRole authRole = AuthRoleBoConvert.instance.convertToBoAuthRole(authRoleBO);
        int count = authRoleService.update(authRole);
        return count > 0;
    }

    @Override
    public Boolean deleteRole(AuthRoleBO authRoleBO) {
        AuthRole authRole = AuthRoleBoConvert.instance.convertToBoAuthRole(authRoleBO);
        authRole.setIsDeleted(IsDeletedEnum.DELETED.getCode());
        int count = authRoleService.update(authRole);
        return count > 0;
    }
}
